using System.Data;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
namespace ContentBanner {
    public class Migrations : DataMigrationImpl {
        public int Create()
        {
            SchemaBuilder.CreateTable("ContentBannerPartRecord", table =>
                table.ContentPartRecord()
                .Column("DisplayBanner", DbType.Boolean));

            ContentDefinitionManager.AlterPartDefinition("ContentBannerPart", builder =>
                builder
                    .Attachable()
                    .WithField("BannerImageUrl", fld =>
                        fld.OfType("MediaPickerField")
                        .WithDisplayName("Banner Image")));

            ContentDefinitionManager.AlterTypeDefinition("Page", builder =>
                builder.WithPart("ContentBannerPart"));

            ContentDefinitionManager.AlterTypeDefinition("ProjectionPage", builder =>
                builder.WithPart("ContentBannerPart"));

            return 1;
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.CreateTable("ContentBannerSettingsPartRecord",table =>
                table.ContentPartRecord()
                .Column<string>("Zone")
                .Column<string>("Position")
                );

            return 2;
        }
    }
}